package com.dgut.finaldemo.controller;

import com.dgut.finaldemo.entity.TeacherHealth;
import com.dgut.finaldemo.service.TeacherHealthService;
import com.dgut.finaldemo.util.R;
import com.dgut.finaldemo.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TeacherHealthController {
    @Autowired
    private TeacherHealthService teacherHealthService;

    @RequestMapping("/teacherHealth")
    @ResponseBody
    public DataVO teacherList(Integer page,Integer limit){
        return teacherHealthService.findData(page,limit);
    }

    @GetMapping("/teacherHealthHtml")
    public String teacherHealthHtml(){
        return "teacherHealth";
    }

    @GetMapping("/teacherDayHealthHtml")
    public String teacherDayHealthHtml(){
        return "teacherDayHealth";
    }

    @RequestMapping("teacherHealth/addTeacherHealthSubmit")
    @ResponseBody
    public R addTeacherHealthSubmit(TeacherHealth teacherHealth, Model model){
        Integer flag = teacherHealthService.addTeacherHealth(teacherHealth);
        if(flag==1){
            model.addAttribute("MESSAGE","添加成功！");
        }else{
            model.addAttribute("MESSAGE","账号学号不一致！");
        }
        return R.ok();
    }

    @RequestMapping("teacherHealth/updateTeacherHealthSubmit")
    @ResponseBody
    public R updateTeacherHealthSubmit(TeacherHealth teacherHealth){
        teacherHealthService.updateTeacherHealth(teacherHealth);
        return R.ok();
    }

    @RequestMapping("teacherHealth/deleteTeacherHealthById")
    @ResponseBody
    public R deleteTeacherHealthById(Integer hid){
        teacherHealthService.deleteTeacherHealthById(hid);
        return R.ok();
    }

    @RequestMapping("teacherHealth/searchTeacherHealth")
    @ResponseBody
    public DataVO searchTeacherHealth(Integer page,Integer limit,
                                      TeacherHealth teacherHealth,
                                      Float maxTemperature){
        return teacherHealthService.searchTeacherHealth(page, limit, teacherHealth, maxTemperature);
    }

    @RequestMapping("/teacherDayHealth")
    @ResponseBody
    public DataVO searchStudentHealthByDay(Integer page,Integer limit){
        return teacherHealthService.searchTeacherHealthByDay(page, limit);
    }

}
